package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.EmployeePosition;
import com.ktgj.customer.service.IEmployeePositionService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 员工角色中间Controller
 * 
 * @author ruoyi
 * @date 2022-07-06
 */
@RestController
@RequestMapping("/employeePosition")
public class EmployeePositionController extends BaseController
{
    @Autowired
    private IEmployeePositionService employeePositionService;

    /**
     * 查询员工角色中间列表
     */
    @PreAuthorize(hasPermi = "customer:position:list")
    @GetMapping("/list")
    public TableDataInfo list(EmployeePosition employeePosition)
    {
        startPage();
        List<EmployeePosition> list = employeePositionService.selectEmployeePositionList(employeePosition);
        return getDataTable(list);
    }

    /**
     * 导出员工角色中间列表
     */
    @PreAuthorize(hasPermi = "customer:position:export")
    @Log(title = "员工角色中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmployeePosition employeePosition) throws IOException
    {
        List<EmployeePosition> list = employeePositionService.selectEmployeePositionList(employeePosition);
        ExcelUtil<EmployeePosition> util = new ExcelUtil<EmployeePosition>(EmployeePosition.class);
        util.exportExcel(response, list, "员工角色中间数据");
    }

    /**
     * 获取员工角色中间详细信息
     */
    @PreAuthorize(hasPermi = "customer:position:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(employeePositionService.selectEmployeePositionById(id));
    }

    /**
     * 新增员工角色中间
     */
    @PreAuthorize(hasPermi = "customer:position:add")
    @Log(title = "员工角色中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmployeePosition employeePosition)
    {
        return toAjax(employeePositionService.insertEmployeePosition(employeePosition));
    }

    /**
     * 修改员工角色中间
     */
    @PreAuthorize(hasPermi = "customer:position:edit")
    @Log(title = "员工角色中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmployeePosition employeePosition)
    {
        return toAjax(employeePositionService.updateEmployeePosition(employeePosition));
    }

    /**
     * 删除员工角色中间
     */
    @PreAuthorize(hasPermi = "customer:position:remove")
    @Log(title = "员工角色中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(employeePositionService.deleteEmployeePositionByIds(ids));
    }
}
